﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using log4net;
using System.Reflection;
using RecruitStudents.Utility.Config;

namespace RecruitStudents.Utility.Log
{
    public class LogManual
    {
        /// <summary>
        /// 写入Mac日志
        /// </summary>
        /// <param name="strFileName"></param>
        /// <param name="strMsg"></param>
        public static void WriteInfo_Mac(string strFileName, string strMsg)
        {
            log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%m");
            log4net.Appender.FileAppender appender = new log4net.Appender.FileAppender(layout, GetPath_Mac(strFileName), true);
            log4net.Config.BasicConfigurator.Configure(appender);
            ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            log.Info(strMsg + " \n ");
            LogManager.Shutdown();
        }
        /// <summary>
        /// 写入错误日志
        /// </summary>
        /// <param name="strFileName"></param>
        /// <param name="strMsg"></param>
        public static void WriteInfo_Error(string strFileName, string strMsg)
        {
            log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%m");
            log4net.Appender.FileAppender appender = new log4net.Appender.FileAppender(layout, GetPath_Error(strFileName), true);
            log4net.Config.BasicConfigurator.Configure(appender);
            ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            log.Info(strMsg + " \n ");
            LogManager.Shutdown();
        }
        /// <summary>
        /// 写入接收信息日志
        /// </summary>
        /// <param name="strFileName">生成的文件名</param>
        /// <param name="strMsg">发送的xml格式的数据</param>
        public static void WriteInfo_Receive(string strFileName, string strMsg)
        {
            log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%m");
            log4net.Appender.FileAppender appender = new log4net.Appender.FileAppender(layout, GetPath_Receive(strFileName), true);
            log4net.Config.BasicConfigurator.Configure(appender);
            ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            log.Info(strMsg + " \n ");
            LogManager.Shutdown();
        }
        /// <summary>
        /// 返回信息日志
        /// </summary>
        /// <param name="strFileName">生成的文件名</param>
        /// <param name="strMsg">发送的xml格式的数据</param>
        public static void WriteInfo_Send(string strFileName, string strMsg)
        {
            log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%m");
            log4net.Appender.FileAppender appender = new log4net.Appender.FileAppender(layout, GetPath_Send(strFileName), true);
            log4net.Config.BasicConfigurator.Configure(appender);
            ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            log.Info(strMsg + " \n ");
            LogManager.Shutdown();
        }
        /// <summary>
        /// 获取【接收】数据的文件目录，并检查目录是否存在，如果不存在，则建立目录
        /// </summary>
        /// <param name="strFileName">生成的文件名</param>
        /// <returns></returns>
        public static string GetPath_Receive(string strFileName)
        {
            string strGetPath = GlobalHelper.pathRoot + "FileList\\Receive\\" + DateTime.Now.DateTimeToyyyy_MM_dd();
            if (!Directory.Exists(strGetPath))
            {
                Directory.CreateDirectory(strGetPath);
            }
            string strPath = Path.Combine(strGetPath, strFileName);
            return strPath;
        }
        /// <summary>
        /// 获取【发送】数据的文件目录，并检查目录是否存在，如果不存在，则建立目录
        /// </summary>
        /// <param name="strFileName">生成的文件名</param>
        /// <returns></returns>
        public static string GetPath_Send(string strFileName)
        {
            string strSendPatn = GlobalHelper.pathRoot + "FileList\\Send\\" + DateTime.Now.DateTimeToyyyy_MM_dd();
            if (!Directory.Exists(strSendPatn))
            {
                Directory.CreateDirectory(strSendPatn);
            }
            string strPath = Path.Combine(strSendPatn, strFileName);
            return strPath;
        }
        /// <summary>
        /// 获取【发送】错误日志的文件目录，并检查目录是否存在，如果不存在，则建立目录
        /// </summary>
        /// <param name="strFileName">生成的文件名</param>
        /// <returns></returns>
        public static string GetPath_Error(string strFileName)
        {
            string strSendPatn = GlobalHelper.pathRoot + "FileList\\Error\\" + DateTime.Now.DateTimeToyyyy_MM_dd();
            if (!Directory.Exists(strSendPatn))
            {
                Directory.CreateDirectory(strSendPatn);
            }
            string strPath = Path.Combine(strSendPatn, strFileName);
            return strPath;
        } 

        public static string GetPath_Mac(string strFileName)
        {
            string strSendPatn = GlobalHelper.pathRoot + "FileList\\Mac\\" + DateTime.Now.DateTimeToyyyy_MM_dd();
            if (!Directory.Exists(strSendPatn))
            {
                Directory.CreateDirectory(strSendPatn);
            }
            string strPath = Path.Combine(strSendPatn, strFileName);
            return strPath;
        }


    }
}
